<?php
return [
    'module' => [
        'name' => 'upload_file',
        'title' => '文件管理',
        'table' => 'upload_files',
    ],
    
    'fields' => [
        'id' => [
            'type' => 'int',
            'length' => 10,
            'comment' => '主键ID',
            'primary' => true,
            'auto_increment' => true,
            'nullable' => false,
            'required' => true,
            'unsigned' => true,
        ],
        'original_name' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '原始文件名',
            'required' => true,
            'nullable' => false,
        ],
        'file_name' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '保存的文件名',
            'required' => true,
            'nullable' => false,
        ],
        'file_path' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '文件访问路径',
            'required' => true,
            'nullable' => false,
        ],
        'file_type' => [
            'type' => 'varchar',
            'length' => 50,
            'comment' => '文件类型',
            'nullable' => true,
            'options' => [
                'image' => '图片',
                'document' => '文档',
                'video' => '视频',
                'audio' => '音频'
            ],
        ],
        'extension' => [
            'type' => 'varchar',
            'length' => 50,
            'comment' => '文件扩展名',
            'required' => true,
            'nullable' => false,
        ],
        'size' => [
            'type' => 'int',
            'length' => 10,
            'comment' => '文件大小(字节)',
            'required' => true,
            'nullable' => false,
            'unsigned' => true,
        ],
        'mime_type' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '文件MIME类型',
            'required' => true,
            'nullable' => false,
        ],
        'upload_by' => [
            'type' => 'int',
            'length' => 10,
            'comment' => '上传者ID',
            'nullable' => true,
            'unsigned' => true,
        ],
        'status' => [
            'type' => 'tinyint',
            'length' => 1,
            'comment' => '状态',
            'nullable' => false,
            'default' => 1,
            'options' => [
                0 => '禁用',
                1 => '启用'
            ],
        ],
        'created_at' => [
            'type' => 'timestamp',
            'comment' => '创建时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true
        ],
        'updated_at' => [
            'type' => 'timestamp',
            'comment' => '更新时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true,
            'extra' => 'ON UPDATE CURRENT_TIMESTAMP'
        ],
    ],
    
    'relations' => [
        'uploader' => [
            'type' => 'belongsTo',
            'model' => 'Admin',
            'foreign_key' => 'upload_by',
        ],
    ],
    
    'queries' => [
        'file_type' => ['=', '?'],
        'upload_by' => ['=', '?'],
        'status' => ['=', '?'],
        'original_name' => ['like', '%?%'],
        'created_at' => ['between', '?,?'],
    ],
]; 